<?php


/**
* TypeBiere
*/
class TypeBiere
{ 
  private $no;
  private $type;

  function __construct( $config)
  {
    foreach( $config as $key => $value )
      $this->{$key} = property_exists( get_class($this), $key) ? $value : null;  
  }

  /**
   * 
   * [getList description]
   * @param  [type] $fileName [description]
   * @return [type]           Retourne un array contenant les informations des type
   */
  static function getList($filePath)
  {
    $document = new DOMDocument;
    $document->load($filePath);
 
    $types = $document->getElementsByTagName('type');

    $typesObjects = array();
    foreach( $types as $type )
      array_push( $typesObjects, new TypeBiere( array('no' =>$type->getAttribute("id"), 'type' => $type->nodeValue ) ) );

    return $typesObjects;
  }

  /**
   * Retourne l'objet si l'élément $attribut == $valeur est présent dans $liste
   * Retourne null si l'objet n'est pas présent
   * @param  [type] $listeDegres [description]
   * @param  [type] $attribute   [description]
   * @param  [type] $value       [description]
   * @return [type]              [description]
   */
  static function getByAttribute( $liste, $attribut, $valeur)
  {
    foreach ($liste as $key => $type) {
      if($type->get($attribut) == $valeur)
        return $type;
    }
    return null;
  }



  public function get( $key )
  {
    if ( property_exists( get_class($this), $key ) )
      return $this->{$key};
    else
      return null;
  }

  public function set( $key, $value )
  {
    if ( property_exists( get_class($this), $key ) )
      $this->{$key} = $value;
  }
}

?>